/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jobportal.college;
import java.sql.*;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import jobportal.Dbconn;

/**
 *
 * @author project
 */
public class abc extends HttpServlet {
   
 

   
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        doPost(request, response);
    } 

   
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
         Connection con;
        Statement st;
        ResultSet rs;
        String error = "";
        boolean flag = true;
        String clgid, password, tponame,tpoemail,clgname,address,state,city,clgprofile,contact,fax,mobile,uname,url,sql;

        PrintWriter out = response.getWriter();
        try {
            con = Dbconn.getConn();
            st = con.createStatement();
            clgid = request.getParameter("clgid");
            password = request.getParameter("password");
            tponame=request.getParameter("tponame");
            tpoemail=request.getParameter("tpoemail");
            clgname=request.getParameter("clgname");
            address=request.getParameter("address");
            state=request.getParameter("state");
            city=request.getParameter("city");
            clgprofile=request.getParameter("clgprofile");
            contact = request.getParameter("contact");
            fax=request.getParameter("fax");
            mobile=request.getParameter("mobile");
            uname=request.getParameter("uname");
            url=request.getParameter("url");
            rs = st.executeQuery("select * from college where clgid='" + clgid + "'");
            if (rs.next()) {
                response.sendRedirect("/college.jsp?status=Id already exist");
            } else {
                sql = "insert into college(clgid,password,tponame,tpoemail,clgname,address,state,city,clgprofile,contact,fax,mobile,uname,url) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
                PreparedStatement ps = con.prepareStatement(sql);
                ps.setString(1, clgid);
                ps.setString(2, password);
                ps.setString(3, tponame);
                ps.setString(4, tpoemail);
                ps.setString(5,clgname);
                ps.setString(6,address);
                ps.setString(7,state);
                ps.setString(8,city);
                ps.setString(9,clgprofile);
                ps.setString(10, contact);
                ps.setString(11, fax);
                ps.setString(12, mobile);
                ps.setString(13, uname);
                ps.setString(14, url);
                ps.executeUpdate();
            }
        } catch (Exception e) {
            out.println(e);
        }
    }

  

}
